<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog ms-modal-dialog">
 <div class="modal-content">

  <div class="modal-header">
   <button type="button" class="close" data-dismiss="modal">
    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
   </button>
   <h4 class="modal-title">权限管理&nbsp;-&nbsp;过滤查询</h4>
  </div>

  <form class="form-horizontal ms-form form-personal-info" method="GET" action="${ctx.host}/principals">

   <input type="hidden" name="filter" value="true" />

   <div class="modal-body">
    <div class="form-group  ms-form-group">
     <label class="control-label col-xs-3">用户名：</label>
     <div class="col-xs-8">
      <input type="text" class="form-control" name="username" tabindex="4" placeholder="支持模糊查询" autocomplete="off" />
     </div>
    </div>

    <div class="form-group  ms-form-group sponsor-user">
     <label class="control-label col-xs-3">姓名：</label>
     <div class="col-xs-8">
      <input type="text" class="form-control" name="name" tabindex="4" placeholder="支持模糊查询" autocomplete="off" />
     </div>
    </div>

    <div class="form-group  ms-form-group">
     <label class="control-label col-xs-3">电话：</label>
     <div class="col-xs-8">
      <input type="text" class="form-control" name="mobile" tabindex="4" placeholder="支持模糊查询" autocomplete="off" />
     </div>
    </div>

   <c:choose>
    <c:when test="${currentPrincipal.admin}">
    <div class="form-group ms-form-group">
     <label class="col-xs-3 control-label">角色：</label>
     <div class="col-xs-8">
      <select name="authority" class="select2  form-control"  tabindex="3">
       <option></option>
       <c:forEach var="role" items="${persist.roles}">
        <option value="${role.code}">${role.description}</option>
       </c:forEach>
      </select>
     </div>
    </div>

    <div class="form-group ms-form-group">
     <label class="col-xs-3 control-label">所在分区：</label>
     <div class="col-xs-8">
      <select name="districtId" class="select2  form-control"  tabindex="3">
       <option></option>
       <c:forEach var="district" items="${persist.districts}">
        <option value="${district.id}">${district.name}</option>
       </c:forEach>
      </select>
     </div>
    </div>
    </c:when>
    <c:otherwise>
      <input type="hidden" name="authority" value="SALE_USER" />
      <input type="hidden" name="districtId" value="${currentPrincipal.district.id}" />
    </c:otherwise>
   </c:choose>

   </div>
   <div class="modal-footer ms-modal-footer">
    <button type="submit" class="btn ms-btn btn-primary">确定</button>
    <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
   </div>
  </form>
 </div>
</div>


<script type="text/javascript">
    $(document).ready(function() {
        $('select[name="authority"]').select2({
            theme : "classic",
            placeholder : '请选择角色',
            minimumResultsForSearch : -1,
            allowClear : true
        });
        $('select[name="districtId"]').select2({
            theme : "classic",
            placeholder : '请选择分区',
            minimumResultsForSearch : -1,
            allowClear : true
        });
    })
</script>